package cn.jbt.api.admin.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.jbt.api.admin.annotation.Log;
import cn.jbt.api.admin.entity.SysPost;
import cn.jbt.api.admin.service.ISysPostService;
import cn.jbt.common.PageQryParam;
import cn.jbt.common.PageQryResult;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotEmpty;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/system/post")
@Slf4j
@AllArgsConstructor
public class SysPostController {

    private final ISysPostService iSysPostService;

    @PostMapping("/list")
    @SaCheckPermission("system:post:list")
    @Log(bizType = "查询", bizName = "分页查询岗位信息")
    public PageQryResult<SysPost> getAllByPage(@Valid @RequestBody PageQryParam<SysPost> pageQryParam) {
        return iSysPostService.getAllByPage(pageQryParam);
    }

    @PostMapping("/add")
    @SaCheckPermission("system:post:add")
    @Log(bizType = "新增", bizName = "新增岗位信息")
    public SysPost add(@Valid @RequestBody SysPost sysPost) {
        return iSysPostService.add(sysPost);
    }

    @PostMapping("/edit")
    @SaCheckPermission("system:post:edit")
    @Log(bizType = "编辑", bizName = "编辑岗位信息")
    public SysPost edit(@Valid @RequestBody SysPost sysPost) {
        return iSysPostService.edit(sysPost);
    }

    @PostMapping("/del")
    @SaCheckPermission("system:post:del")
    @Log(bizType = "删除", bizName = "删除岗位信息")
    public void del(@NotEmpty @RequestBody List<Long> ids) {
        iSysPostService.del(ids);
    }

}
